﻿#region

using System;

#endregion

namespace TvdbLib
{
    /// <summary>
    ///     Logs internal messages
    /// </summary>
    public static class Log
    {
        #region Fields

        private static LOGLEVEL m_currentLogLevel = LOGLEVEL.Warn;

        #endregion Fields

        #region Enumerations

        /// <summary>
        ///     Loglevel
        /// </summary>
        public enum LOGLEVEL
        {
            /// <summary>
            ///     Logs debug messages
            /// </summary>
            Debug = 0,

            /// <summary>
            ///     Logs info messages
            /// </summary>
            Info = 1,

            /// <summary>
            ///     Logs warn messages
            /// </summary>
            Warn = 2,

            /// <summary>
            ///     Logs error messages
            /// </summary>
            Error = 3,

            /// <summary>
            ///     Logs fatal messages
            /// </summary>
            Fatal = 4
        }

        #endregion Enumerations

        #region Properties

        /// <summary>
        ///     The loglevel that is currently used (default = warn)
        /// </summary>
        public static LOGLEVEL LogLevel
        {
            get { return m_currentLogLevel; }
            set { m_currentLogLevel = value; }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        ///     Logs the message at level Debug
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        internal static void Debug(String _logMessage)
        {
            WriteLogMessage(_logMessage, LOGLEVEL.Debug);
        }

        /// <summary>
        ///     Logs the message at level Debug
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_ex"> Exception to log </param>
        internal static void Debug(String _logMessage, Exception _ex)
        {
            WriteLogMessage(_logMessage + _ex, LOGLEVEL.Debug);
        }

        /// <summary>
        ///     Logs the message at level Error
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        internal static void Error(String _logMessage)
        {
            WriteLogMessage(_logMessage, LOGLEVEL.Error);
        }

        /// <summary>
        ///     Logs the message at level Error
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_ex"> Exception to log </param>
        internal static void Error(String _logMessage, Exception _ex)
        {
            WriteLogMessage(_logMessage + _ex, LOGLEVEL.Error);
        }

        /// <summary>
        ///     Logs the message at level Fatal
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        internal static void Fatal(String _logMessage)
        {
            WriteLogMessage(_logMessage, LOGLEVEL.Fatal);
        }

        /// <summary>
        ///     Logs the message at level Fatal
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_ex"> Exception to log </param>
        internal static void Fatal(String _logMessage, Exception _ex)
        {
            WriteLogMessage(_logMessage + _ex, LOGLEVEL.Fatal);
        }

        /// <summary>
        ///     Logs the message at level info
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        internal static void Info(String _logMessage)
        {
            WriteLogMessage(_logMessage, LOGLEVEL.Info);
        }

        /// <summary>
        ///     Logs the message at level info
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_ex"> Exception to log </param>
        internal static void Info(String _logMessage, Exception _ex)
        {
            WriteLogMessage(_logMessage + _ex, LOGLEVEL.Info);
        }

        /// <summary>
        ///     Logs the message at level Warn
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        internal static void Warn(String _logMessage)
        {
            WriteLogMessage(_logMessage, LOGLEVEL.Warn);
        }

        /// <summary>
        ///     Logs the message at level Warn
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_ex"> Exception to log </param>
        internal static void Warn(String _logMessage, Exception _ex)
        {
            WriteLogMessage(_logMessage + _ex, LOGLEVEL.Warn);
        }

        /// <summary>
        ///     Logs the message at the given level
        /// </summary>
        /// <param name="_logMessage"> Message to log </param>
        /// <param name="_level"> Level to log </param>
        internal static void WriteLogMessage(String _logMessage, LOGLEVEL _level)
        {
            if (_level >= m_currentLogLevel)
            {
                switch (_level)
                {
                    case LOGLEVEL.Debug:
                        //debug log processing
                        Console.WriteLine(_logMessage);
                        break;
                    case LOGLEVEL.Info:
                        //debug log processing
                        Console.WriteLine(_logMessage);
                        break;
                    case LOGLEVEL.Warn:
                        //debug log processing
                        Console.WriteLine(_logMessage);
                        break;
                    case LOGLEVEL.Error:
                        //debug log processing
                        Console.WriteLine(_logMessage);
                        break;
                    case LOGLEVEL.Fatal:
                        //debug log processing
                        Console.WriteLine(_logMessage);
                        break;
                }
            }
        }

        #endregion Methods
    }
}